package com.nip.miniproject.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.nip.miniproject.comons.Constant;
import com.nip.miniproject.datatransferobject.PersonalEntity;
import com.nip.trainnig.R;

/**
 * @author DuyenPK
 * 
 */
public class InformationActivity extends Activity {

	private PersonalEntity _personal;
	private TextView tvUserName;
	private TextView tvPassWorld;
	private TextView tvWebsite;
	private String linkWeb;
	private Button btnBack;
	private Button btnGoto;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.infomation_activity);

		Bundle bundle = getIntent().getExtras();

		if (bundle == null) {
			return;
		}

		_personal = (PersonalEntity) bundle.getSerializable(Constant.SEND_CODE);

		this.Initialize();
		this.ShowPersonalInformation(_personal);
	}

	/**
	 * HÃ m khá»Ÿi táº¡o cÃ¡c giÃ¡ trá»‹ máº·c Ä‘á»‹nh
	 * 
	 */
	private void Initialize() {
		tvUserName = (TextView) findViewById(R.id.tvIUser);
		tvPassWorld = (TextView) findViewById(R.id.tvIPass);
		tvWebsite = (TextView) findViewById(R.id.tvIWebsite);
		btnBack = (Button) findViewById(R.id.btnBack);
		btnGoto = (Button) findViewById(R.id.btnGoto);
		btnBack.setOnClickListener(new MyEvent());
		btnGoto.setOnClickListener(new MyEvent());
	}

	/**
	 * gÃ¡n thÃ´ng tin ngÆ°á»�i dÃ¹ng lÃªn giao diá»‡n
	 * 
	 * @param personal
	 */
	private void ShowPersonalInformation(PersonalEntity personal) {

		if (personal == null) {
			return;
		}

		this.tvPassWorld.setText(personal.getPassWorld());
		this.tvUserName.setText(personal.getUserName());
		this.tvWebsite.setText(personal.getWebsite());
		this.linkWeb = personal.getWebsite();
	}

	/**
	 * Show web view activity
	 * 
	 * @param linkWeb
	 *            link to website
	 */
	private void ShowWebViewActivity(String linkWeb) {
		Intent i = new Intent(this, WebViewActivity.class);
		i.putExtra(Constant.SEND_CODE_01, linkWeb);
		startActivity(i);
	}

	/**
	 * Call back to regist activity
	 */
	private void CallBackRegistActivity() {
		onBackPressed();
	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		super.onBackPressed();
	}

	/**
	 * Class contain event of activity
	 * 
	 * @author ThangNM
	 * 
	 */
	private class MyEvent implements OnClickListener {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			AnalysisButtonClick(v);
		}

		/**
		 * Analysis button click
		 * 
		 * @param v
		 *            button click
		 */
		private void AnalysisButtonClick(View v) {
			int id = v.getId();
			switch (id) {
			case R.id.btnBack:
				CallBackRegistActivity();
				break;
			case R.id.btnGoto:
				ShowWebViewActivity(linkWeb);
				break;

			default:
				break;
			}
		}
	}
}
